/* 

Пример реализации реляционной модели 
EAV/CR – Entity-Attribute-Value with Classes and Relationships 
(Сущность-Атрибут-Значение с Классами и Отношениями)." 

*/
drop table OBJTYPE CASCADE CONSTRAINTS;
drop table ATTRTYPE CASCADE CONSTRAINTS;
drop table OBJECTS CASCADE CONSTRAINTS;
drop table ATTRIBUTES CASCADE CONSTRAINTS;
drop table OBJREFERENCE CASCADE CONSTRAINTS;

CREATE TABLE OBJTYPE
  (
    OBJECT_TYPE_ID NUMBER(20) NOT NULL ENABLE,
    PARENT_ID      NUMBER(20),
    CODE           VARCHAR2(20) NOT NULL UNIQUE,
    NAME           VARCHAR2(200 BYTE),
    DESCRIPTION    VARCHAR2(1000 BYTE),
	ORDERED        NUMBER,
    CONSTRAINT CON_OBJECT_TYPE_ID PRIMARY KEY (OBJECT_TYPE_ID),
    CONSTRAINT CON_PARENT_ID FOREIGN KEY (PARENT_ID) REFERENCES OBJTYPE (OBJECT_TYPE_ID) ON DELETE CASCADE ENABLE
  );

COMMENT ON TABLE OBJTYPE IS 'Таблица описаний объектных типов';
 
COMMENT ON COLUMN OBJTYPE.OBJECT_TYPE_ID IS 'Идентификатор объектного типа';
COMMENT ON COLUMN OBJTYPE.PARENT_ID IS 'ссылка на идентификатор родительского объектного типа';
COMMENT ON COLUMN OBJTYPE.CODE IS 'название объектного типа в английской кодировке';
COMMENT ON COLUMN OBJTYPE.NAME IS 'название объектного типа в национальной кодировке (для GUI)';
COMMENT ON COLUMN OBJTYPE.DESCRIPTION IS 'разверное описание объектного типа в национальной кодировке (для GUI)';


/* При переходе от UML-диаграмме к EAV-модели рекомендуется:
1) имена классов представить как OBJTYPE.name
2) связь типа "обобщение" представить в виде связи между OBJTYPE.OBJECT_TYPE_ID и OBJTYPE.PARENT_ID
3) связь типа "агрегатная ассоциация" представить в виде связи между OBJTYPE.id и OBJTYPE.PARENT_ID
*/

INSERT INTO OBJTYPE (OBJECT_TYPE_ID,PARENT_ID,CODE,NAME,DESCRIPTION) VALUES (777,NULL,'GAME','ИГРА',NULL);
INSERT INTO OBJTYPE (OBJECT_TYPE_ID,PARENT_ID,CODE,NAME,DESCRIPTION) VALUES (1,777,'BOARD','ДОСКА',NULL);
INSERT INTO OBJTYPE (OBJECT_TYPE_ID,PARENT_ID,CODE,NAME,DESCRIPTION) VALUES (8,1,'CELLS','ЯЧЕЙКИ',NULL);
--INSERT INTO OBJTYPE (OBJECT_TYPE_ID,PARENT_ID,CODE,NAME,DESCRIPTION) VALUES (24,8,'CELL_POSITION','',NULL);
INSERT INTO OBJTYPE (OBJECT_TYPE_ID,PARENT_ID,CODE,NAME,DESCRIPTION) VALUES (3,8,'PROPERTY_CELL','',NULL);
INSERT INTO OBJTYPE (OBJECT_TYPE_ID,PARENT_ID,CODE,NAME,DESCRIPTION) VALUES (7,3,'BUILDINGS','',NULL);
INSERT INTO OBJTYPE (OBJECT_TYPE_ID,PARENT_ID,CODE,NAME,DESCRIPTION) VALUES (23,3,'PROPERTY_CELL_STATUS','',NULL);
INSERT INTO OBJTYPE (OBJECT_TYPE_ID,PARENT_ID,CODE,NAME,DESCRIPTION) VALUES (4,8,'EVENT_CELL','',NULL);
INSERT INTO OBJTYPE (OBJECT_TYPE_ID,PARENT_ID,CODE,NAME,DESCRIPTION) VALUES (5,1,'PLAYER','',NULL);
INSERT INTO OBJTYPE (OBJECT_TYPE_ID,PARENT_ID,CODE,NAME,DESCRIPTION) VALUES (6,5,'WALLET','',NULL);
INSERT INTO OBJTYPE (OBJECT_TYPE_ID,PARENT_ID,CODE,NAME,DESCRIPTION) VALUES (10,5,'PLAYER_STATUS','',NULL);
INSERT INTO OBJTYPE (OBJECT_TYPE_ID,PARENT_ID,CODE,NAME,DESCRIPTION) VALUES (14,8,'COLOR','',NULL);
INSERT INTO OBJTYPE (OBJECT_TYPE_ID,PARENT_ID,CODE,NAME,DESCRIPTION) VALUES (15,7,'BUILDING_LEVEL','',NULL);
INSERT INTO OBJTYPE (OBJECT_TYPE_ID,PARENT_ID,CODE,NAME,DESCRIPTION) VALUES (16,NULL,'EVENT','',NULL);
INSERT INTO OBJTYPE (OBJECT_TYPE_ID,PARENT_ID,CODE,NAME,DESCRIPTION) VALUES (17,16,'BEGIN_EVENT','',NULL);
INSERT INTO OBJTYPE (OBJECT_TYPE_ID,PARENT_ID,CODE,NAME,DESCRIPTION) VALUES (18,16,'EMERGENCY_EVENT','',NULL);
INSERT INTO OBJTYPE (OBJECT_TYPE_ID,PARENT_ID,CODE,NAME,DESCRIPTION) VALUES (22,1,'MONOPOLY','',NULL);
INSERT INTO OBJTYPE (OBJECT_TYPE_ID,PARENT_ID,CODE,NAME,DESCRIPTION) VALUES (25,5,'PENALTY','',NULL);
INSERT INTO OBJTYPE (OBJECT_TYPE_ID,PARENT_ID,CODE,NAME,DESCRIPTION) VALUES (26,7,'BUILDING_TYPE','',NULL);
INSERT INTO OBJTYPE (OBJECT_TYPE_ID,PARENT_ID,CODE,NAME,DESCRIPTION) VALUES (27,NULL,'USER','',NULL)

-- Пример команды создания таблицы типов атрибутов:
CREATE TABLE ATTRTYPE (
    ATTR_ID      		NUMBER(20) NOT NULL ENABLE,
    OBJECT_TYPE_ID 		NUMBER(20) NOT NULL ENABLE,
	OBJECT_TYPE_ID_REF 	NUMBER(20),
    CODE         		VARCHAR2(20),
    NAME         		VARCHAR2(200 BYTE),
    CONSTRAINT CON_ATTR_ID PRIMARY KEY (ATTR_ID),
    CONSTRAINT CON_ATTR_OBJECT_TYPE_ID FOREIGN KEY (OBJECT_TYPE_ID) REFERENCES OBJTYPE (OBJECT_TYPE_ID) ENABLE,
	CONSTRAINT CON_ATTR_OBJECT_TYPE_ID_REF FOREIGN KEY (OBJECT_TYPE_ID_REF) REFERENCES OBJTYPE (OBJECT_TYPE_ID) ENABLE
);

 
COMMENT ON TABLE ATTRTYPE IS 'Таблица описаний атрибутных типов';
 
-- ПРИМЕРЫ ЗАПОЛНЕНИЯ ТАБЛИЦ:
INSERT INTO ATTRTYPE (ATTR_ID,OBJECT_TYPE_ID,OBJECT_TYPE_ID_REF,CODE,NAME) VALUES (14,1,NULL,'SAVE_NAME','');
INSERT INTO ATTRTYPE (ATTR_ID,OBJECT_TYPE_ID,OBJECT_TYPE_ID_REF,CODE,NAME) VALUES (1,5,6,'MONEY','');
INSERT INTO ATTRTYPE (ATTR_ID,OBJECT_TYPE_ID,OBJECT_TYPE_ID_REF,CODE,NAME) VALUES (2,5,NULL,'PLAYER_POSITION','');
INSERT INTO ATTRTYPE (ATTR_ID,OBJECT_TYPE_ID,OBJECT_TYPE_ID_REF,CODE,NAME) VALUES (3,5,NULL,'NAME','');
INSERT INTO ATTRTYPE (ATTR_ID,OBJECT_TYPE_ID,OBJECT_TYPE_ID_REF,CODE,NAME) VALUES (11,5,10,'PLAYER_STATUS','');
INSERT INTO ATTRTYPE (ATTR_ID,OBJECT_TYPE_ID,OBJECT_TYPE_ID_REF,CODE,NAME) VALUES (9999,14,22,'COLOR','');
INSERT INTO ATTRTYPE (ATTR_ID,OBJECT_TYPE_ID,OBJECT_TYPE_ID_REF,CODE,NAME) VALUES (4,15,15,'LEVEL1','');
INSERT INTO ATTRTYPE (ATTR_ID,OBJECT_TYPE_ID,OBJECT_TYPE_ID_REF,CODE,NAME) VALUES (5,16,15,'LEVEL2','');
INSERT INTO ATTRTYPE (ATTR_ID,OBJECT_TYPE_ID,OBJECT_TYPE_ID_REF,CODE,NAME) VALUES (6,17,15,'LEVEL3','');
INSERT INTO ATTRTYPE (ATTR_ID,OBJECT_TYPE_ID,OBJECT_TYPE_ID_REF,CODE,NAME) VALUES (7,7,NULL,'PRICE','');
INSERT INTO ATTRTYPE (ATTR_ID,OBJECT_TYPE_ID,OBJECT_TYPE_ID_REF,CODE,NAME) VALUES (9,2,22,'MONOPOLY','');
INSERT INTO ATTRTYPE (ATTR_ID,OBJECT_TYPE_ID,OBJECT_TYPE_ID_REF,CODE,NAME) VALUES (12,3,5,'OWNER','');
INSERT INTO ATTRTYPE (ATTR_ID,OBJECT_TYPE_ID,OBJECT_TYPE_ID_REF,CODE,NAME) VALUES (13,3,7,'BUILDING_POSITION','');
INSERT INTO ATTRTYPE (ATTR_ID,OBJECT_TYPE_ID,OBJECT_TYPE_ID_REF,CODE,NAME) VALUES (10,22,NULL,'MONOPOLY_TYPE','');
INSERT INTO ATTRTYPE (ATTR_ID,OBJECT_TYPE_ID,OBJECT_TYPE_ID_REF,CODE,NAME) VALUES (16,7,23,'BUILDING_STATUS','');
INSERT INTO ATTRTYPE (ATTR_ID,OBJECT_TYPE_ID,OBJECT_TYPE_ID_REF,CODE,NAME) VALUES (17,8,NULL,'CELL_POSITION','');
----!!!!!! ATTR_ID 18, 19 ПОСМОТРЕТЬ
INSERT INTO ATTRTYPE (ATTR_ID,OBJECT_TYPE_ID,OBJECT_TYPE_ID_REF,CODE,NAME) VALUES (18,25,NULL,'PENALTY_LEVEL','');--18 ПОМЕНЯТЬ НАЗВАНИЕ С 19
INSERT INTO ATTRTYPE (ATTR_ID,OBJECT_TYPE_ID,OBJECT_TYPE_ID_REF,CODE,NAME) VALUES (19,25,15,'PENALTY','');---------------
INSERT INTO ATTRTYPE (ATTR_ID,OBJECT_TYPE_ID,OBJECT_TYPE_ID_REF,CODE,NAME) VALUES (21,26,25,'PENALTY_TYPE_BUILD','');
INSERT INTO ATTRTYPE (ATTR_ID,OBJECT_TYPE_ID,OBJECT_TYPE_ID_REF,CODE,NAME) VALUES (22,27,5,'LOGIN','');
INSERT INTO ATTRTYPE (ATTR_ID,OBJECT_TYPE_ID,OBJECT_TYPE_ID_REF,CODE,NAME) VALUES (23,27,5,'PASSWORD','');
INSERT INTO ATTRTYPE (ATTR_ID,OBJECT_TYPE_ID,OBJECT_TYPE_ID_REF,CODE,NAME) VALUES (24,27,5,'E-MAIL','');

 -- Пример команды создания таблицы объектов:
CREATE TABLE OBJECTS
  (
    OBJECT_ID      NUMBER(20) NOT NULL ENABLE,
    PARENT_ID      NUMBER(20),
    OBJECT_TYPE_ID NUMBER(20) NOT NULL ENABLE,
    NAME           VARCHAR2(2000 BYTE),
    DESCRIPTION    VARCHAR2(4000 BYTE),
    CONSTRAINT CON_OBJECTS_ID PRIMARY KEY (OBJECT_ID),
    CONSTRAINT CON_PARENTS_ID FOREIGN KEY (PARENT_ID) REFERENCES OBJECTS (OBJECT_ID) ON DELETE CASCADE DEFERRABLE ENABLE,
    CONSTRAINT CON_OBJ_TYPE_ID FOREIGN KEY (OBJECT_TYPE_ID) REFERENCES OBJTYPE (OBJECT_TYPE_ID) ENABLE
  );

COMMENT ON TABLE OBJECTS IS 'Таблица описаний экземпляров объектов';

-- Пример заполнения таблицы
INSERT INTO OBJECTS (OBJECT_ID,PARENT_ID,OBJECT_TYPE_ID,NAME,DESCRIPTION) VALUES (1,NULL,777,'GAME1',NULL);
INSERT INTO OBJECTS (OBJECT_ID,PARENT_ID,OBJECT_TYPE_ID,NAME,DESCRIPTION) VALUES (2,1,1,'BOARD1',NULL);
INSERT INTO OBJECTS (OBJECT_ID,PARENT_ID,OBJECT_TYPE_ID,NAME,DESCRIPTION) VALUES (3,2,22,'MONO1',NULL);
INSERT INTO OBJECTS (OBJECT_ID,PARENT_ID,OBJECT_TYPE_ID,NAME,DESCRIPTION) VALUES (4,2,22,'MONO2',NULL);
INSERT INTO OBJECTS (OBJECT_ID,PARENT_ID,OBJECT_TYPE_ID,NAME,DESCRIPTION) VALUES (5,2,22,'MONO3',NULL);
INSERT INTO OBJECTS (OBJECT_ID,PARENT_ID,OBJECT_TYPE_ID,NAME,DESCRIPTION) VALUES (6,2,22,'MONO4',NULL);
INSERT INTO OBJECTS (OBJECT_ID,PARENT_ID,OBJECT_TYPE_ID,NAME,DESCRIPTION) VALUES (7,3,8,'CELL1',NULL);
INSERT INTO OBJECTS (OBJECT_ID,PARENT_ID,OBJECT_TYPE_ID,NAME,DESCRIPTION) VALUES (8,3,8,'CELL2',NULL);
INSERT INTO OBJECTS (OBJECT_ID,PARENT_ID,OBJECT_TYPE_ID,NAME,DESCRIPTION) VALUES (9,3,8,'CELL3',NULL);
INSERT INTO OBJECTS (OBJECT_ID,PARENT_ID,OBJECT_TYPE_ID,NAME,DESCRIPTION) VALUES (10,3,8,'CELL4',NULL);
INSERT INTO OBJECTS (OBJECT_ID,PARENT_ID,OBJECT_TYPE_ID,NAME,DESCRIPTION) VALUES (11,3,8,'CELL5',NULL);
INSERT INTO OBJECTS (OBJECT_ID,PARENT_ID,OBJECT_TYPE_ID,NAME,DESCRIPTION) VALUES (12,4,8,'CELL6',NULL);
INSERT INTO OBJECTS (OBJECT_ID,PARENT_ID,OBJECT_TYPE_ID,NAME,DESCRIPTION) VALUES (13,4,8,'CELL7',NULL);
INSERT INTO OBJECTS (OBJECT_ID,PARENT_ID,OBJECT_TYPE_ID,NAME,DESCRIPTION) VALUES (14,4,8,'CELL8',NULL);
INSERT INTO OBJECTS (OBJECT_ID,PARENT_ID,OBJECT_TYPE_ID,NAME,DESCRIPTION) VALUES (15,4,8,'CELL9',NULL);
INSERT INTO OBJECTS (OBJECT_ID,PARENT_ID,OBJECT_TYPE_ID,NAME,DESCRIPTION) VALUES (16,4,8,'CELL10',NULL);
INSERT INTO OBJECTS (OBJECT_ID,PARENT_ID,OBJECT_TYPE_ID,NAME,DESCRIPTION) VALUES (17,5,8,'CELL11',NULL);
INSERT INTO OBJECTS (OBJECT_ID,PARENT_ID,OBJECT_TYPE_ID,NAME,DESCRIPTION) VALUES (18,5,8,'CELL12',NULL);
INSERT INTO OBJECTS (OBJECT_ID,PARENT_ID,OBJECT_TYPE_ID,NAME,DESCRIPTION) VALUES (19,5,8,'CELL13',NULL);
INSERT INTO OBJECTS (OBJECT_ID,PARENT_ID,OBJECT_TYPE_ID,NAME,DESCRIPTION) VALUES (20,5,8,'CELL14',NULL);
INSERT INTO OBJECTS (OBJECT_ID,PARENT_ID,OBJECT_TYPE_ID,NAME,DESCRIPTION) VALUES (21,5,8,'CELL15',NULL);
INSERT INTO OBJECTS (OBJECT_ID,PARENT_ID,OBJECT_TYPE_ID,NAME,DESCRIPTION) VALUES (22,6,8,'CELL16',NULL);
INSERT INTO OBJECTS (OBJECT_ID,PARENT_ID,OBJECT_TYPE_ID,NAME,DESCRIPTION) VALUES (23,6,8,'CELL17',NULL);
INSERT INTO OBJECTS (OBJECT_ID,PARENT_ID,OBJECT_TYPE_ID,NAME,DESCRIPTION) VALUES (24,6,8,'CELL18',NULL);
INSERT INTO OBJECTS (OBJECT_ID,PARENT_ID,OBJECT_TYPE_ID,NAME,DESCRIPTION) VALUES (25,6,8,'CELL19',NULL);
INSERT INTO OBJECTS (OBJECT_ID,PARENT_ID,OBJECT_TYPE_ID,NAME,DESCRIPTION) VALUES (26,6,8,'CELL20',NULL);
INSERT INTO OBJECTS (OBJECT_ID,PARENT_ID,OBJECT_TYPE_ID,NAME,DESCRIPTION) VALUES (27,2,8,'CPEC_CELL1',NULL);
INSERT INTO OBJECTS (OBJECT_ID,PARENT_ID,OBJECT_TYPE_ID,NAME,DESCRIPTION) VALUES (28,2,8,'CPEC_CELL2',NULL);
INSERT INTO OBJECTS (OBJECT_ID,PARENT_ID,OBJECT_TYPE_ID,NAME,DESCRIPTION) VALUES (29,2,8,'CPEC_CELL3',NULL);
INSERT INTO OBJECTS (OBJECT_ID,PARENT_ID,OBJECT_TYPE_ID,NAME,DESCRIPTION) VALUES (30,2,8,'CPEC_CELL4',NULL);
INSERT INTO OBJECTS (OBJECT_ID,PARENT_ID,OBJECT_TYPE_ID,NAME,DESCRIPTION) VALUES (31,2,5,'PLAYER1',NULL);
INSERT INTO OBJECTS (OBJECT_ID,PARENT_ID,OBJECT_TYPE_ID,NAME,DESCRIPTION) VALUES (32,2,5,'PLAYER2',NULL);
INSERT INTO OBJECTS (OBJECT_ID,PARENT_ID,OBJECT_TYPE_ID,NAME,DESCRIPTION) VALUES (33,7,7,'BUILDING1',NULL);
INSERT INTO OBJECTS (OBJECT_ID,PARENT_ID,OBJECT_TYPE_ID,NAME,DESCRIPTION) VALUES (34,8,7,'BUILDING2',NULL);
INSERT INTO OBJECTS (OBJECT_ID,PARENT_ID,OBJECT_TYPE_ID,NAME,DESCRIPTION) VALUES (35,9,7,'BUILDING3',NULL);
INSERT INTO OBJECTS (OBJECT_ID,PARENT_ID,OBJECT_TYPE_ID,NAME,DESCRIPTION) VALUES (36,10,7,'BUILDING4',NULL);
INSERT INTO OBJECTS (OBJECT_ID,PARENT_ID,OBJECT_TYPE_ID,NAME,DESCRIPTION) VALUES (37,11,7,'BUILDING5',NULL);
INSERT INTO OBJECTS (OBJECT_ID,PARENT_ID,OBJECT_TYPE_ID,NAME,DESCRIPTION) VALUES (38,12,7,'BUILDING6',NULL);
INSERT INTO OBJECTS (OBJECT_ID,PARENT_ID,OBJECT_TYPE_ID,NAME,DESCRIPTION) VALUES (39,13,7,'BUILDING7',NULL);
INSERT INTO OBJECTS (OBJECT_ID,PARENT_ID,OBJECT_TYPE_ID,NAME,DESCRIPTION) VALUES (40,2,22,'MONO5',NULL);
INSERT INTO OBJECTS (OBJECT_ID,PARENT_ID,OBJECT_TYPE_ID,NAME,DESCRIPTION) VALUES (41,2,22,'MONO6',NULL);
INSERT INTO OBJECTS (OBJECT_ID,PARENT_ID,OBJECT_TYPE_ID,NAME,DESCRIPTION) VALUES (42,2,22,'MONO7',NULL);
INSERT INTO OBJECTS (OBJECT_ID,PARENT_ID,OBJECT_TYPE_ID,NAME,DESCRIPTION) VALUES (43,2,22,'MONO8',NULL);
INSERT INTO OBJECTS (OBJECT_ID,PARENT_ID,OBJECT_TYPE_ID,NAME,DESCRIPTION) VALUES (44,2,22,'MONO9',NULL);
INSERT INTO OBJECTS (OBJECT_ID,PARENT_ID,OBJECT_TYPE_ID,NAME,DESCRIPTION) VALUES (45,NULL,25,'PENALTY',NULL);

-- Пример команды создания таблицы значений атрибутов:
CREATE TABLE ATTRIBUTES
  (
    ATTR_ID    NUMBER(20) NOT NULL ENABLE,
    OBJECT_ID  NUMBER(20) NOT NULL ENABLE,
    VALUE      VARCHAR2(4000 BYTE),
    DATE_VALUE DATE,
    CONSTRAINT CON_AOBJECT_ID FOREIGN KEY (OBJECT_ID) REFERENCES OBJECTS (OBJECT_ID) ON DELETE CASCADE ENABLE,
    CONSTRAINT CON_AATTR_ID FOREIGN KEY (ATTR_ID) REFERENCES ATTRTYPE (ATTR_ID) ON DELETE CASCADE ENABLE
  );  

COMMENT ON TABLE ATTRIBUTES IS 'Таблица описаний атрибутов экземпляров объектов';
COMMENT ON COLUMN ATTRIBUTES.VALUE IS 'Значение атрибута экземпляра объекта в виде строки или числа';
COMMENT ON COLUMN ATTRIBUTES.DATE_VALUE IS 'Значение атрибута экземпляра объекта в виде даты';

INSERT INTO ATTRIBUTES(ATTR_ID, OBJECT_ID, value, date_value) VALUES(14,2,'SAVE1', null);
INSERT INTO ATTRIBUTES(ATTR_ID, OBJECT_ID, value, date_value) VALUES(1,31,'1500', null);
INSERT INTO ATTRIBUTES(ATTR_ID, OBJECT_ID, value, date_value) VALUES(1,32,'1500', null);
INSERT INTO ATTRIBUTES(ATTR_ID, OBJECT_ID, value, date_value) VALUES(3,31,'IVANOV', null);
INSERT INTO ATTRIBUTES(ATTR_ID, OBJECT_ID, value, date_value) VALUES(3,32,'PETROV', null);
INSERT INTO ATTRIBUTES(ATTR_ID, OBJECT_ID, value, date_value) VALUES(10,3,'MONO_TYPE1', null);
INSERT INTO ATTRIBUTES(ATTR_ID, OBJECT_ID, value, date_value) VALUES(10,4,'MONO_TYPE2', null);
INSERT INTO ATTRIBUTES(ATTR_ID, OBJECT_ID, value, date_value) VALUES(10,5,'MONO_TYPE3', null);
INSERT INTO ATTRIBUTES(ATTR_ID, OBJECT_ID, value, date_value) VALUES(10,6,'MONO_TYPE4', null);
INSERT INTO ATTRIBUTES(ATTR_ID, OBJECT_ID, value, date_value) VALUES(10,40,'MONO_TYPE5', null);
INSERT INTO ATTRIBUTES(ATTR_ID, OBJECT_ID, value, date_value) VALUES(10,41,'MONO_TYPE6', null);
INSERT INTO ATTRIBUTES(ATTR_ID, OBJECT_ID, value, date_value) VALUES(10,42,'MONO_TYPE7', null);
INSERT INTO ATTRIBUTES(ATTR_ID, OBJECT_ID, value, date_value) VALUES(10,43,'MONO_TYPE8', null);
INSERT INTO ATTRIBUTES(ATTR_ID, OBJECT_ID, value, date_value) VALUES(10,44,'MONO_TYPE9', null);
INSERT INTO ATTRIBUTES(ATTR_ID, OBJECT_ID, value, date_value) VALUES(9999,3,'GREEN', null);
INSERT INTO ATTRIBUTES(ATTR_ID, OBJECT_ID, value, date_value) VALUES(9999,4,'BLUE', null);
INSERT INTO ATTRIBUTES(ATTR_ID, OBJECT_ID, value, date_value) VALUES(9999,5,'ORANGE', null);
INSERT INTO ATTRIBUTES(ATTR_ID, OBJECT_ID, value, date_value) VALUES(9999,6,'RED', null);
INSERT INTO ATTRIBUTES(ATTR_ID, OBJECT_ID, value, date_value) VALUES(9999,40,'BLACK', null);
INSERT INTO ATTRIBUTES(ATTR_ID, OBJECT_ID, value, date_value) VALUES(9999,41,'YELLOW', null);
INSERT INTO ATTRIBUTES(ATTR_ID, OBJECT_ID, value, date_value) VALUES(9999,42,'PINK', null);
INSERT INTO ATTRIBUTES(ATTR_ID, OBJECT_ID, value, date_value) VALUES(9999,43,'WHITE', null);
INSERT INTO ATTRIBUTES(ATTR_ID, OBJECT_ID, value, date_value) VALUES(9999,44,'BROWN', null);
INSERT INTO ATTRIBUTES(ATTR_ID, OBJECT_ID, value, date_value) VALUES(11,31,'ACTIVE', null);
INSERT INTO ATTRIBUTES(ATTR_ID, OBJECT_ID, value, date_value) VALUES(11,32,'WAIT', null);
INSERT INTO ATTRIBUTES(ATTR_ID, OBJECT_ID, value, date_value) VALUES(7,33,'100', null);
INSERT INTO ATTRIBUTES(ATTR_ID, OBJECT_ID, value, date_value) VALUES(17,7,'1', null);
INSERT INTO ATTRIBUTES(ATTR_ID, OBJECT_ID, value, date_value) VALUES(17,8,'2', null);
INSERT INTO ATTRIBUTES(ATTR_ID, OBJECT_ID, value, date_value) VALUES(17,9,'3', null);
INSERT INTO ATTRIBUTES(ATTR_ID, OBJECT_ID, value, date_value) VALUES(17,10,'4', null);
INSERT INTO ATTRIBUTES(ATTR_ID, OBJECT_ID, value, date_value) VALUES(17,11,'5', null);
INSERT INTO ATTRIBUTES(ATTR_ID, OBJECT_ID, value, date_value) VALUES(17,12,'6', null);
INSERT INTO ATTRIBUTES(ATTR_ID, OBJECT_ID, value, date_value) VALUES(17,13,'7', null);
INSERT INTO ATTRIBUTES(ATTR_ID, OBJECT_ID, value, date_value) VALUES(17,14,'8', null);
INSERT INTO ATTRIBUTES(ATTR_ID, OBJECT_ID, value, date_value) VALUES(17,15,'9', null);
INSERT INTO ATTRIBUTES(ATTR_ID, OBJECT_ID, value, date_value) VALUES(17,16,'10', null);
INSERT INTO ATTRIBUTES(ATTR_ID, OBJECT_ID, value, date_value) VALUES(17,17,'11', null);
INSERT INTO ATTRIBUTES(ATTR_ID, OBJECT_ID, value, date_value) VALUES(17,18,'12', null);
INSERT INTO ATTRIBUTES(ATTR_ID, OBJECT_ID, value, date_value) VALUES(17,19,'13', null);
INSERT INTO ATTRIBUTES(ATTR_ID, OBJECT_ID, value, date_value) VALUES(17,20,'14', null);
INSERT INTO ATTRIBUTES(ATTR_ID, OBJECT_ID, value, date_value) VALUES(17,21,'15', null);
INSERT INTO ATTRIBUTES(ATTR_ID, OBJECT_ID, value, date_value) VALUES(17,22,'16', null);
INSERT INTO ATTRIBUTES(ATTR_ID, OBJECT_ID, value, date_value) VALUES(17,23,'17', null);
INSERT INTO ATTRIBUTES(ATTR_ID, OBJECT_ID, value, date_value) VALUES(17,24,'18', null);
INSERT INTO ATTRIBUTES(ATTR_ID, OBJECT_ID, value, date_value) VALUES(17,25,'19', null);
INSERT INTO ATTRIBUTES(ATTR_ID, OBJECT_ID, value, date_value) VALUES(17,26,'20', null);
INSERT INTO ATTRIBUTES(ATTR_ID, OBJECT_ID, value, date_value) VALUES(17,27,'21', null);
INSERT INTO ATTRIBUTES(ATTR_ID, OBJECT_ID, value, date_value) VALUES(17,28,'22', null);
INSERT INTO ATTRIBUTES(ATTR_ID, OBJECT_ID, value, date_value) VALUES(17,29,'23', null);
INSERT INTO ATTRIBUTES(ATTR_ID, OBJECT_ID, value, date_value) VALUES(18,31,'-50', null);--ВЫЧЕСТЬ -50$ С ИГРОКА
INSERT INTO ATTRIBUTES(ATTR_ID, OBJECT_ID, value, date_value) VALUES(22,31,'PLAYER_1_LOGIN', null);
INSERT INTO ATTRIBUTES(ATTR_ID, OBJECT_ID, value, date_value) VALUES(23,31,'PASSWORD_1', null);
INSERT INTO ATTRIBUTES(ATTR_ID, OBJECT_ID, value, date_value) VALUES(24,31,'MAIL_1', null);


-- Пример команды создания таблицы связей:
CREATE TABLE OBJREFERENCE
  (
    ATTR_ID   NUMBER(20) NOT NULL ENABLE,
    REFERENCE NUMBER(20) NOT NULL ENABLE,
    OBJECT_ID NUMBER(20) NOT NULL ENABLE,
    CONSTRAINT CON_REFERENCE FOREIGN KEY (REFERENCE) REFERENCES OBJECTS (OBJECT_ID) ON DELETE CASCADE ENABLE,
    CONSTRAINT CON_ROBJECT_ID FOREIGN KEY (OBJECT_ID) REFERENCES OBJECTS (OBJECT_ID) ON DELETE CASCADE ENABLE,
    CONSTRAINT CON_RATTR_ID FOREIGN KEY (ATTR_ID) REFERENCES ATTRTYPE (ATTR_ID) ON DELETE CASCADE ENABLE
  ); 

COMMENT ON TABLE OBJREFERENCE IS 'Таблица описаний связей между экземплярами объектов';
COMMENT ON COLUMN OBJREFERENCE.ATTR_ID IS 'Тип связи между экземплярами объектов как атрибутный тип';
COMMENT ON COLUMN OBJREFERENCE.OBJECT_ID IS 'Ссылка на экземпляр 1-го объекта в связи "простая ассоциация"';
COMMENT ON COLUMN OBJREFERENCE.REFERENCE IS 'Ссылка на экземпляр 2-го объекта в связи "простая ассоциация"';


/* При переходе от UML-диаграмме к ORM рекомендуется:
4) связь типа "простая ассоциация" представить в виде связи между OBJREFERENCE.OBJECT_ID и OBJREFERENCE.REFERENCE
*/
-- Пример описания связи между сотрудниками и подразделдением
INSERT INTO OBJREFERENCE (ATTR_ID,REFERENCE,OBJECT_ID) VALUES (2,27,31);
INSERT INTO OBJREFERENCE (ATTR_ID,REFERENCE,OBJECT_ID) VALUES (2,24,32);
INSERT INTO OBJREFERENCE (ATTR_ID,REFERENCE,OBJECT_ID) VALUES (12,32,33);
INSERT INTO OBJREFERENCE (ATTR_ID,REFERENCE,OBJECT_ID) VALUES (4,26,33);
INSERT INTO OBJREFERENCE (ATTR_ID,REFERENCE,OBJECT_ID) VALUES (18,33,31);

CREATE SEQUENCE get_id_seq START WITH 1 MAXVALUE 999999 INCREMENT BY 1 NOCACHE CYCLE;
-- Функция для получения уникального id 

CREATE OR REPLACE FUNCTION get_id RETURN NUMBER
  AS
    v_ret NUMBER;
  BEGIN
    SELECT to_number(TO_CHAR(sysdate,'yyyymmddhh24miss') || lpad(TO_CHAR(get_id_seq.nextval),6,'0'))
      INTO v_ret
    FROM DUAL;
    RETURN v_ret;
  END;
 /
-- пример использования

select get_id from dual;
